<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/commons/include/html_doctype.html" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<%@include file="/commons/page/codegen.jsp" %>
		<script type="text/javascript" src="${ctx}/js/gpoint/rdp/door/door.js"></script>
		<title>TB_DOOR_DOOR管理列表</title>
	</head>
	<body>
		<div class="wrapper wrapper-content  animated fadeInRight col-sm-12">
			<div  class="toolbar-panel ">
				<div class="toolbar-box">
					<div class="toolbar-head clearfix">
						<!-- 顶部按钮 -->
						<div class="buttons"> 		
							<a class="btn btn-primary fa fa-search" href="javascript:void(0);" ><span>搜索</span></a>
							<a class="btn btn-primary fa fa-edit" href="javascript:void(0);"  action="${ctx}/rdp/door/door/edit.htm" ><span>编辑</span></a>	
							
							<!-- <a href="javascript:void(0);" class="btn btn-primary fa" id="checkParam"  onclick ="checkParam();" ><span>查看</span></a>
				            <a href="javascript:void(0);" class="btn btn-primary fa" id="sendParam"  onclick ="saveNetAndLocal();" ><span>下发</span></a>	 -->	
							<a href="javascript:void(0);" class="btn btn-primary fa" id="sendParam"  onclick ="opendoor();" ><span>远程开门</span></a>	
							<!--  
							<a class="btn btn-primary fa fa-add"   href="${ctx}/rdp/door/door/edit.htm" ><span>添加</span></a>					       
					        <a class="btn btn-primary fa fa-remove" href="javascript:void(0);"  action="${ctx}/rdp/door/door/remove.htm"><span>删除</span></a>
					        -->
						</div>
						<!-- 收缩 -->
						<div class="tools">
							<a href="javascript:void(0);" class="collapse">
								<i class="bigger-180 fa  fa-angle-double-up"></i>
							</a>
						</div>
					</div>
					<!-- #查询条件-->
					<div class="toolbar-body" >
						<form role="form" class="search-form">
							<div  class="form-inline p-xxs">
								<div class="form-group">
									<label   class="search-label">控制器名称</label>:
									<input type="text"  name="Q^CONTROLLERNAME^SL"  class="form-control"  />
								</div> 
								<div class="form-group">
									<label   class="search-label">门名称</label>:
									<input type="text"  name="Q^DOORNAME^SL"  class="form-control"  />
								</div> 
								<div class="form-group">
									<label   class="search-label">门编号</label>:
									<input type="text"  name="Q^DOORNO^SL"  class="form-control"  />
								</div> 
							</div> 
						</form>
					</div><!--/ 查询条件-->
				</div>
			</div><!--/ 操作、查询-->
			<div class="jqGrid_wrapper">
				<table id="doorGrid" ></table>
				<div id="doorPager"></div>
			</div>
		</div>
	<script type="text/javascript">
	
	function saveNetAndLocal(){
		
		//alert("下发执行");
		
		//获取参数，这里调用控制器的方法进行下发
		 //获取显示的记录
		  var ids = jQuery("#doorGrid").jqGrid('getGridParam','selarrrow');
	       if(ids.length != 1){
	    	   DialogUtil.confirm("请选择一个选项");
	    	   return;
	       }
	     //  var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
	        
		var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
		 //获取数值
		 console.log(rowData);
		    //获取SN
		    sn=rowData.doorno.substring(0,9);
		    //获取door
		    door=rowData.doorno.substring(10,11);
		    
		    kzfs=rowData.doorcontrol;
		    //控制方式
		     if("常开"==kzfs){
		    	 controller=1;
		     }else if("常闭"==kzfs){
		    	 controller=2;
		     }else if("在线控制"==kzfs){
		    	 controller=3;
		     }
		    //开门延时
		    opendelay=rowData.doordelay;
		    
		        
		   
		  //后台设置：
	      //var url="http://192.168.0.186:8025/setDoorMessage?";
		var url="http://115.159.58.87:8989/pluss-unite-page/setDoorMessage?";
		  setSingleDoor(url,sn,door,controller,opendelay);
		//比对操作 这里dialog   如何返回数值，进行保存：
		//调用接口保存
	}
	
	
	
	 function setSingleDoor(url,snParam,doorParam,pcn,pdn){
		 var result = false;
		 var contactChar="&";
		 var snParam = "sn="+snParam;
		 var doorParam="door="+doorParam;
		 var controllerParam = "controller="+pcn;
		 var opendelayParam = "opendelay="+ pdn;
		 var seetingUrl =url+snParam+contactChar+doorParam+contactChar+controllerParam+contactChar+opendelayParam;
		 
		 $.ajax({
				url : seetingUrl,
				type : "GET",
				contentType : "application/json",
				//data:JSON.stringify(map),
				dataType : "json",
				async : false,
				success : function(data) {
					console.log(data);
					if(null==data|| ''==data){
						result=false;
						alert("下发异常");
					}else{
						result=true;
						alert("下发成功");
					}  
					
					
				},
				error:function(xhr,textStatus){
					alert("下发失败");
				}
		   
			});					 
		 return result;				 
	 }
	 
	 
	 
	 function checkParam(){	
		 
		 //获取显示的记录
		  var ids = jQuery("#doorGrid").jqGrid('getGridParam','selarrrow');
	       if(ids.length != 1){
	    	   DialogUtil.confirm("请选择一个选项");
	    	   return;
	       }
	     //  var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
	        
		var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
		 //获取数值
		 console.log(rowData);
		 //获取id
		 // var  type=ids[0];
		    
		 //获取SN
         	 // sn=$("#sn").val();
		    doorno=rowData.doorno;
		    
         	  sn=doorno.substring(0,9);
         	 //获取列门号
         	 
             //door=$("#door").val();
              door=doorno.substring(10,11);
         	 //alert("carduid="+carduid);
         	 //调用接口获取时间参数
         	// alert("sn="+sn+","+"door="+door);
            DialogUtil.dialog(
					 {
			 				title : "网络门信息",
			 				content : '${ctx}/rdp/zoneCTL/doorController/netDetail1.htm?sn='+sn+'&door='+door,
			 				area : [ '1000px', '650px' ],
			 				maxmin : false
			 				//end : function() {
							//	$("#doorControllerGrid").trigger("reloadGrid");
							//}
			 			
			 			
			 		}
			 );		
         	 
         	 
         	 
         	 
        
		    	         	 
		    	         	 
		    	         	 
 }
	 
	 
	 
	function getdoorno(){
		 //获取显示的记录
		  var ids = jQuery("#doorGrid").jqGrid('getGridParam','selarrrow');
	       if(ids.length != 1){
	    	   DialogUtil.confirm("请选择一个选项");
	    	   return;
	       }
	     //  var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
	        
		var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
		 //获取数值
		 console.log(rowData);
		
		  
		 //获取id
		 // var  type=ids[0];
		    
		 //获取SN
       	 // sn=$("#sn").val();
		    doorno=rowData.doorno;
		    
		    return doorno;
	}
	
	function opendoor(){
		alert("远程开门执行");
		
		//获取数值beign
		
		//获取的应该是门编号：传递参数应该是设备_门编号例如 ：
//133118548_1

		 //获取显示的记录
		  var ids = jQuery("#doorGrid").jqGrid('getGridParam','selarrrow');
	       if(ids.length != 1){
	    	   DialogUtil.confirm("请选择一个选项");
	    	   return;
	       }
	     //  var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
	        
		var rowData= jQuery("#doorGrid").jqGrid("getRowData",ids[0]);
		 //获取数值
		 console.log(rowData);
		
		  
		 //获取id
		 // var  type=ids[0];
		    
		 //获取SN
     	 // sn=$("#sn").val();
		    doorno=rowData.doorno;    //放在这个位置会影响return
		    
     
         var address='${address}';
         context=address;
       // var context="http://127.0.0.1:8083";
		//校验
		 var map ={};
	     map.doorArr = doorno;
		
		//调用接口
		  $.ajax({
		    	         	type: "post",
		    	         	   url: context+"/remoteByArray",
		    	         	    contentType: "application/json;charset=utf-8;",
		    	         	   data:JSON.stringify(map),
		    	         	  dataType:"json",//注意不是datatype哦
		    	         	    async: false,//使用同步操作，否则init方法执行时setting可能还未被赋值
		    	         	   success: function(data) {
		    	         	          
		    	         	 
				    	         	console.log(data);
			    	         		
		    	         		    if(data.code==200){
		    	         		    	//alert("远程开门成功！");
		    	         		    	 DialogUtil.confirm(data.mess + ',是否继续操作',
													function(rtn) {
													if(rtn){
														window.location.reload(true);
																   
													}   
													else{
														
													}
												    	
													});
		    	         		    	
		    	         		    }else{
		    	         		    	//alert("远程开门异常！");
		    	         		    	 DialogUtil.confirm(data.mess + ',是否继续操作',
													function(rtn) {
													if(rtn){
														window.location.reload(true);
																   
													}   
													else{
														
													}
												    	
													});
		    	         		    	 
		    	         		    }
		    	         	  },
		    	         	 error: function(){
		    	         		 // alert("远程开门失败！");
		    	         		 DialogUtil.confirm(data.mess + ',是否继续操作',
											function(rtn) {
											if(rtn){
												window.location.reload(true);
														   
											}   
											else{
												
											}
										    	
											});
		    	         		 
		    	         		 
		    	              }
		    	         	 });
		    	         	 //end
		
		
	}
	</script>
	</body>
	
</html>